package br.com.neb.caronamanager.view;

import java.util.Date;
import java.util.List;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import br.com.neb.caronamanager.R;
import br.com.neb.caronamanager.model.Carona;
import br.com.neb.caronamanager.model.dao.DB;

public class HomeFragment extends Fragment{

	public HomeFragment(){}
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
  
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);
  
        Button btnInsert = (Button) rootView.findViewById(R.id.btnInsert);
        btnInsert.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				DB db = new DB(v.getContext());
				Integer date = (int)new Date().getTime()/1000;
				db.insert(new Carona(date,"Bruno",1));
			}
		});
        
        Button btnRead = (Button) rootView.findViewById(R.id.btnRead);
        btnRead.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				DB  db = new DB(v.getContext());
				List<Carona> list = db.search();
				
				String result = "";
				for(Carona t : list)
				{
					result += t.toString();
				}
				
				Toast.makeText(v.getContext(), "Valor inseridos: " + result, Toast.LENGTH_LONG).show();
				
			}
		});
        
        return rootView;
    }
	
}
